<template>
  <div class="page-home">
    <div class="home-entry">
      <div class="container">
        <!-- 左侧分类 -->
        <homeCategoryVue />
        <!-- banner轮播图 -->
        <homeBannerVue />
        <!-- 13.1新鲜好物 -->
        <homePanelVue title="新鲜好物" sub-title="新鲜出炉 品质靠谱">
          <template #right>
            <XtxMore></XtxMore>
          </template>
          <template #main>
            <ul ref="pannel" class="goods-list">
              <li v-for="item in store" :key="item.id">
                <!-- 17.2让路由后面接参数id -->
                <RouterLink :to="`/good/${item.id}`">
                  <img :src="item.picture" alt="" />
                  <p class="name">{{ item.name }}</p>
                  <p class="price">&yen;{{ item.price }}</p>
                </RouterLink>
              </li>
            </ul>
          </template>
        </homePanelVue>
        <!-- 13.1 人气推荐-->
        <homePanelVue title="人气推荐" sub-title="人气爆款 不容错过">
          <template #main>
            <ul class="goods-list">
              <li v-for="item in list" :key="item.id">
                <RouterLink to="/">
                  <img alt="" v-lazy-img="item.picture" />
                  <p class="name">{{ item.title }}</p>
                  <p class="desc">{{ item.alt }}</p>
                </RouterLink>
              </li>
            </ul></template
          >
        </homePanelVue>
      </div>
    </div>
  </div>
</template>
<script>
import homeCategoryVue from './components/home-category.vue'
import homeBannerVue from './components/home-banner.vue'
import homePanelVue from './components/home-panel.vue'
import { findNew, findHot } from '@/api/home.js'
import { ref } from 'vue'
export default {
  name: 'PageHome',
  components: { homeCategoryVue, homeBannerVue, homePanelVue },
  setup () {
    // 新鲜好物
    const store = ref([])
    async function findNewList () {
      const res = await findNew()
      store.value = res.result
    }
    // 人气推荐
    const list = ref([])
    async function findHotList () {
      const res = await findHot()
      list.value = res.result
    }
    findNewList()
    findHotList()
    return {
      store,
      list
    }
  }
}
</script>
<style scoped lang='less'>
.goods-list {
  display: flex;
  justify-content: space-between;
  height: 406px;
  li {
    width: 306px;
    height: 406px;
    background: #f0f9f4;
    img {
      width: 306px;
      height: 306px;
    }
    p {
      font-size: 22px;
      padding-top: 12px;
      text-align: center;
      text-overflow: ellipsis;
      overflow: hidden;
      white-space: nowrap;
    }
    .price {
      color: @priceColor;
    }
  }
}
</style>
